/* Chinese initialisation for the jQuery UI date picker plugin. */
/* Written by Cloudream (cloudream@gmail.com). */
( function( factory ) {
  if ( typeof define === "function" && define.amd ) {

    // AMD. Register as an anonymous module.
    define( [ "../widgets/datepicker" ], factory );
  } else {

    // Browser globals
    factory( jQuery.datepicker );
  }
}( function( datepicker ) {


datepicker.regional[ "zh-CN" ] = {
  closeText: "关闭",
  prevText: "&#x3C;上月",
  nextText: "下月&#x3E;",
  currentText: "今天",
  monthNames: [ "一月","二月","三月","四月","五月","六月",
  "七月","八月","九月","十月","十一月","十二月" ],
  monthNamesShort: [ "一月","二月","三月","四月","五月","六月",
  "七月","八月","九月","十月","十一月","十二月" ],
  dayNames: [ "星期日","星期一","星期二","星期三","星期四","星期五","星期六" ],
  dayNamesShort: [ "周日","周一","周二","周三","周四","周五","周六" ],
  dayNamesMin: [ "日","一","二","三","四","五","六" ],
  weekHeader: "周",
  dateFormat: "yy-mm-dd",
  firstDay: 1,
  isRTL: false,
  showMonthAfterYear: true,
  yearSuffix: "年",
  maxDate:"今天",
  defaultDate:pdate1,
  beforeShowDay:function(date){
		var month = date.getMonth()+1;
		var date1=date.getDate();
		var tmpdate=date.getFullYear()+""+(month<10?"0"+month:month)+""+(date1<10?'0'+date1:date1)+"";
		if(ptype == "tfzb"){
			if(tmpdate > '20170320'){
				var isOrdered = false;
				for (i = 0; i < paperall.length; i++) { 
				  if (date.getMonth()+1 == paperall[i].substring(5,7) && date.getDate() == paperall[i].substring(8,10) && date.getFullYear() == paperall[i].substring(0,4))  
				  {  
					isOrdered = true;break;  
				  }  
				}  
				if(isOrdered){
					if (date.getMonth()+1 == pdate1.substring(5,7) && date.getDate() == pdate1.substring(8,10) && date.getFullYear() == pdate1.substring(0,4))  
					{  
						return [true, 'highlight'];  
					}else{
						return [true, ''];  
					}
				}else{  
					return [false, 'CLOSED'];  
				}
			}else{
				return [true, 'highlight'];  

			}
		}else{
			if(tmpdate > '20160929'){
				var isOrdered = false;
				for (i = 0; i < paperall.length; i++) { 
				  if (date.getMonth()+1 == paperall[i].substring(5,7) && date.getDate() == paperall[i].substring(8,10) && date.getFullYear() == paperall[i].substring(0,4))  
				  {  
					isOrdered = true;break;  
				  }  
				}  
				if(isOrdered){
					if (date.getMonth()+1 == pdate1.substring(5,7) && date.getDate() == pdate1.substring(8,10) && date.getFullYear() == pdate1.substring(0,4))  
					{  
						return [true, 'highlight'];  
					}else{
						return [true, ''];  
					}
				}else{  
					return [false, 'CLOSED'];  
				}
			}else{
				return [true, 'highlight'];  

			}
		}
	},
	 onChangeMonthYear: function(year, month,inst){
		$(".date-box").datepicker("refresh");
	},
	onSelect: function(dateText, inst) {
		str = dateText.split('-'); 
		var day = new Date(); 
		day.setUTCFullYear(str[0], str[1] - 1, str[2]); 
		day.setUTCHours(0, 0, 0, 0);  
		month = day.getMonth()+1;
		date=day.getDate();
		if ((navigator.userAgent.indexOf('MSIE') >= 0) && (navigator.userAgent.indexOf('Opera') < 0))
			var formatdate=(day.getYear())+""+(month<10?'0'+month:month)+""+(date<10?'0'+date:date);
		else
			var formatdate=(day.getYear()+1900)+""+(month<10?'0'+month:month)+""+(date<10?'0'+date:date);
		
		if(ptype == "tfzb"){
			if(formatdate<= '20170320'){
				location.href="http://morning.thecover.cn/new/html/tfzb/"+formatdate+"/index.html";
			}else{
				location.href="/shtml/"+ptype+"/"+formatdate+"/vB1.shtml";
			}
		}else{
			if(formatdate>='20120724' && formatdate<= '20160929'){
				location.href="http://history.thecover.cn/shtml/hxdsb/"+formatdate+"/index.shtml";
			}else if(formatdate<'20120724' && formatdate>='20080806'){
				location.href="http://history.thecover.cn/old/epaper/hxdsb/html/"+(day.getYear()+1900)+"-"+(month<10?'0'+month:month)+"/"+(date<10?'0'+date:date)+"/node_2.htm";
			}else if(formatdate<'20080806' && formatdate>='20070723'){
				location.href="http://history.thecover.cn/old/epaper/hxdsb/html/"+(day.getYear()+1900)+"/"+(month<10?'0'+month:month)+"/"+(date<10?'0'+date:date);
			}else if(formatdate<'20090723'){
				location.href="http://history.thecover.cn/old/epaper/hxdsb/html/"+(day.getYear()+1900)+"/"+(month<10?'0'+month:month)+"/"+(date<10?'0'+date:date);
			}else{
				if(ptype == "hxdsb")
					location.href="/shtml/"+ptype+"/"+formatdate+"/vA1.shtml";
				if(ptype == "szbcdb")
					location.href="/shtml/"+ptype+"/"+formatdate+"/vF1.shtml";
				if(ptype == "szbcn")
					location.href="/shtml/"+ptype+"/"+formatdate+"/vD1.shtml";
				if(ptype == "hxdsbsq")
					location.href="/shtml/"+ptype+"/"+formatdate+"/vE1.shtml";
			}
		}
	}  
  };
  datepicker.setDefaults( datepicker.regional[ "zh-CN" ] );

  return datepicker.regional[ "zh-CN" ];

} ) );